home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / xcontact / parody / linklist.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.6 KB  |  83 lines

  1. // ------------------ linklist.cpp
  2.  
  3. #include "linklist.h"
  4.  
  5. LinkedListEntry::LinkedListEntry(LinkedListHead *lh) :
  6.                                     listhead(lh)
  7. {
  8.     prev = next = NULL;
  9.     if (lh != NULL)
  10.         AppendListEntry();
  11. }
  12.  
  13. // ----- append a list entry to the end of the list
  14. void LinkedListEntry::AppendListEntry(LinkedListHead *lh)
  15. {
  16.     if (lh != NULL)
  17.         listhead = lh;
  18.     if (listhead != NULL)    {
  19.         if (listhead->first == NULL)
  20.             listhead->first = this;
  21.         prev = (LinkedListEntry *) listhead->last;
  22.         if (prev != NULL)
  23.             prev->next = this;
  24.         listhead->last = this;
  25.     }
  26. }
  27.  
  28. // ----- prepend a list entry to the beginning of the list
  29. void LinkedListEntry::PrependListEntry(LinkedListHead *lh)
  30. {
  31.     if (lh != NULL)
  32.         listhead = lh;
  33.     if (listhead != NULL)    {
  34.         if (listhead->last == NULL)
  35.             listhead->last = this;
  36.         next = (LinkedListEntry *) listhead->first;
  37.         if (next != NULL)
  38.             next->prev = this;
  39.         listhead->first = this;
  40.     }
  41. }
  42.  
  43. // --- Insert a list entry ahead of a specified (*fe) entry.
  44. void LinkedListEntry::InsertListEntry(void *fe,
  45.                                                 LinkedListHead *lh)
  46. {
  47.     if (lh != NULL)
  48.         listhead = lh;
  49.     LinkedListEntry *ahd = (LinkedListEntry *) fe;
  50.     if (listhead != NULL)    {
  51.         if (ahd == NULL)
  52.             AppendListEntry();
  53.         else     {
  54.             next = ahd;
  55.             prev = ahd->prev;
  56.             ahd->prev = this;
  57.             if (prev == NULL)
  58.                 listhead->first = this;
  59.             else
  60.                 prev->next = this;
  61.         }
  62.     }
  63. }
  64.  
  65. // ---------- delete a list entry
  66. void LinkedListEntry::DeleteListEntry()
  67. {
  68.     if (listhead != NULL)    {
  69.         if (next != NULL)
  70.             next->prev = prev;
  71.         else 
  72.             listhead->last = prev;
  73.         if (prev != NULL)
  74.             prev->next = next;
  75.         else
  76.             listhead->first = next;
  77.         listhead = NULL;
  78.     }
  79.     next = prev = NULL;
  80. }
  81.  
  82.  
  83.